<template>
    <div>
        <h1>新增居民</h1>
        <h1>哈哈哈哈哈</h1>
        <tbody class="table">
        <tbody>
            <tr>
                <td>头像</td>
                <td>
                    <input type="file" @change="upload">
                    <img style="height: 60px;width: 60px;" :src="axios.defaults.baseURL + data.Img">
                </td>
            </tr>
            <tr>
                <td>居民姓名</td>
                <td>
                    <input type="text" v-model="data.Fname">
                </td>
            </tr>
            <tr>
                <td>手机号</td>
                <td>
                    <input type="text" v-model="data.Phone">
                </td>
            </tr>
            <tr>
                <td>身份证号</td>
                <td>
                    <input type="text" v-model="data.FFZH">
                </td>
            </tr>
            <tr>
                <td>籍贯</td>
                <td>
                    <input type="text" v-model="data.JG">
                </td>
            </tr>
            <tr>
                <td>民族</td>
                <td>
                    <input type="text" v-model="data.MZ">
                </td>
            </tr>
            <tr>
                <td>小区</td>
                <td>
                    <input type="text" v-model="data.XQ">
                </td>
            </tr>
            <tr>
                <td>房间号</td>
                <td>
                    <input type="text" v-model="data.FnameNum">
                </td>
            </tr>
            <tr>
                <td>添加时间</td>
                <td>
                    <input type="date" v-model="data.RZSJ">
                </td>
            </tr>
            <tr>
                <td>Tid</td>
                <td>
                    <select v-model="data.Tid">
                        <option value="0">选择类型</option>
                        <option v-for="d in Bang" :value="d.Tid">{{ d.Tname }}</option>
                    </select>

                </td>
            </tr>
             <tr>
                <td>性别</td>
                <td>
                    <input v-model="data.Set" type="radio" name="Set" value="男">男
                    <input v-model="data.Set" type="radio" name="Set" value="女">女
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input v-model="data.Stare" type="radio" name="Stare" value="1">已审核
                    <input v-model="data.Stare" type="radio" name="Stare" value="2">未审核
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="button" class="btn btn-success" value="新增" @click="saveinfo">
                    <a href="/">返回</a>
                </td>
            </tr>
        </tbody>
        </tbody>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { ref,onMounted} from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
//上传
const upload = (abc: any) => {
    //取文件  创建表单数据对象 把文件保存到表单数据对象
    let f = abc.target.files[0]
    let fd = new FormData();
    fd.append("file", f);

    axios.post("/api/WJSC/UpLoad", fd).then(res => {
        data.value.Img = res.data;
    })
}
onMounted(()=>{
    bang();
})
const bang=()=>{
    axios.get("/api/Foum/bang").then(res=>{
        Bang.value=res.data
    })

}
const Bang=ref([{
    "Tid": 0,
    "Tname": "string"
}])
const data = ref({
   "Fid": 0,
  "Fname": "",
  "Img": "",
  "Tid": 0,
  "Set": "",
  "FFZH": "",
  "Phone": "",
  "JG": "",
  "MZ": "",
  "XQ": "",
  "FnameNum": "",
  "Stare": 0,
  "IsDelete": true,
  "RZSJ": "2025-08-11T07:42:35.203Z",
  "DL": 0
})
const saveinfo = () => {
 let zz=/^1[3-9]\d{9}$/;
    if(!zz.test(data.value.Phone))
    {
       alert("手机格式不对")
       return;
    }
    axios.post('/api/Foum/tianjia', data.value).then(res => {
        if (res.data > 0) {
            alert("新增成功")
            router.push("/showfoum");
        }
        else {
            alert("新增失败...")
        }
    })
}
</script>

<style scoped></style>